<template>
  <div>
    <zbTable ref="tableRef" :api-fun="get_value_card_list" @action="action" />

    <!-- 充值弹窗 -->
    <add
      v-if="showAdd"
      v-model:visible="showAdd"
      @done="done"
      :editData="editData"
    />
    <!-- 申请退款弹窗 -->
    <back
      v-if="showBack"
      v-model:visible="showBack"
      @done="done"
      :editData="editData"
    />
  </div>
</template>
<script setup>
  import { ref, reactive } from 'vue';
  import { message, Modal } from 'ant-design-vue';
  import { actionFn } from '@/utils/action.js';
  import { daochuFn } from '@/utils/daochu.js';
  import { PlusOutlined, UploadOutlined } from '@ant-design/icons-vue';
  import { useRouter } from 'vue-router';
  import zbTable from './components/purchasePurchaseIndex.vue';
  import add from './components/add.vue';
  import back from './components/back.vue';
  import { get_value_card_list } from '@/api/order/value_card';
  // 是否显示编辑弹窗
  const tableRef = ref(null);
  const router = useRouter();
  const { push } = useRouter();
  const editData = ref({});
  const actionData = ref({});

  const showAdd = ref(false);
  const showBack = ref(false);

  const action = (data) => {
    console.log('data', data);
    editData.value = data.row_data;
    actionData.value.url = data.action_data.url;
    if (data.action_data.type == 'detail') {
      push({
        path: '/order/value_card/detail',
        query: {
          member_id: data.row_data.id
        }
      });
    } else if (data.action_data.type == 'recharge') {
      showAdd.value = true;
    } else if (data.action_data.type == 'refund') {
      showBack.value = true;
    }
  };

  const done = (form) => {
    actionFn(actionData.value, form, reloadTable);
  };
  const reloadTable = () => {
    showAdd.value = false;
    showBack.value = false;
    tableRef.value.reload();
  };
</script>
